import matplotlib.pyplot as plt#导入包
# #两个点
# x=[1,2]
# y=[2,4]
# #x轴y轴起止点
# plt.axis([0,10,0,10])
# plt.scatter(x,y)#绘图
# plt.show()#展示框

# #折线图
# input__value=[1,2,3,4,5]#输入值影响x轴起点
# squares=[1,4,9,16,25]#输出值
# plt.plot(input__value,squares,linewidth=5)#linewidth改变线条粗细
# plt.title('Numbers',fontsize=24)#图表标题及字号大小
# plt.xlabel('Value',fontsize=14)#x轴标题及字号大小
# plt.ylabel('ARG',fontsize=14)#y轴标题及字号大小
# plt.tick_params(axis='both',labelsize=14)#设置单位刻度大小
# plt.show()

# #柱状图
# plt.bar(x=(0,1),height=(1,0.5),width=0.35)
# plt.show()

# #多幅子图
# fig=plt.figure()
# p1=fig.add_subplot(211)#画框子图p1
# x=[1,2,3,4,5,6,7,8]
# y=[2,1,3,5,2,6,12,7]
# p1.plot(x,y)
# p2=fig.add_subplot(212)
# a=[1,2]
# b=[2,4]
# p2.scatter(a,b)
# plt.show()

# #3D图
# from mpl_toolkits.mplot3d import Axes3D
# fig=plt.figure()
# ax=fig.add_subplot(111,projection='3d')
# x=[1,1,2,2]
# y=[3,4,4,3]
# z=[1,100,1,1]
# ax.plot_trisurf(x,y,z)
# plt.show()

#图表交互
import random
class Die:
    """一个骰子类"""
    def __init__(self,num_sides=6):
        self.num_sides=num_sides
    def roll(self):
        return random.randint(1,self.num_sides)

import pygal
die=Die()
result_list=[]
#扔1000次
for roll_num in range(1000):
    result=die.roll()
    result_list.append(result)
frequencies=[]
for value in range(1,die.num_sides+1):
    frequency=result_list.count(value)
    frequencies.append(frequency)

#条形图统计
hist=pygal.Bar()
hist.title='Results of rolling one D6 1000 times'
hist.x_labels=[1,2,3,4,5,6]
hist.xtitle='Result'
hist.ytilte='Frequency'
hist.add('D6',frequencies)
hist.render_to_file('die_visual.svg')